import React, { Component } from 'react'
import axios from 'axios'

class Home extends Component {

    state = {
        list: [],
        bt: '大家都在看'
    }

    componentDidMount() {
        axios.get('/api/list').then((res) => {
            this.setState({
                list: res.data
            })
        })
    }

    render() { 
        let { list, bt } = this.state
        return (
            <div>
                <h3 style={{color: 'red'}}>{bt}</h3>
                <ul>
                    {
                        list && list.length ? list.map((item,index) => {
                            return <li key={index}>
                                <span>{item.id}</span>
                                {item.title}
                            </li>
                        }) : ''
                    }
                </ul>
            </div>
        )
    }
}
 
export default Home;